﻿@page "/EditMenu"


<h3>管理菜谱</h3>

<Table TItem="BlazorOrdering.Core.BoMenu"
       
       IsStriped="true" IsBordered="true"
       ShowToolbar="true"
       ShowDefaultButtons="false" ClickToSelect="true" OnClickRowCallback="@ClickRow"
       ShowExtendButtons="true"
       Items="@BoMeuns">
    <TableColumns>
        <TableColumn @bind-Field="@context.Day" Width="180" FormatString="yyyy年MM月dd日 dddd" />
        <TableColumn @bind-Field="@context.Type" Width="100" />
        <TableColumn @bind-Field="@context.Name" />
        <TableColumn @bind-Field="@context.Price" />
    </TableColumns>
    <RowButtonTemplate>
        <TableCellButton Size="Size.None" Color="Color.Danger" 
                         TItem="BlazorOrdering.Core.BoMenu" 
                         Item="@context" Icon="fa fa-remove" Text="删除" 
                         OnClickCallback="@OnRowButtonClick" IsOutline="true" />
    </RowButtonTemplate>
</Table>

<p>当前选中行：@(CurrentItem?.Name ?? "无")</p>

<GroupBox Title="修改菜谱">
    <ValidateForm Model="@CurrentItem" OnValidSubmit="@OnValidSubmit" OnInvalidSubmit="@OnInvalidSubmit">
        <EditorForm TModel="BlazorOrdering.Core.BoMenu" AutoGenerateAllItem="false">
            <FieldItems>
                <EditorItem @bind-Field="@CurrentItem.Day" Readonly="true" />
                <EditorItem @bind-Field="@CurrentItem.Type">
                    <EditTemplate Context="value">
                        @{
                            var model = value as BlazorOrdering.Core.BoMenu;
                        }
                        <div class="form-group col-12">
                            <Select SkipValidate="true" @bind-Value="@CurrentItem!.Type" Items="@Types" ShowSearch="true" />
                        </div>
                    </EditTemplate>
                </EditorItem>
                <EditorItem @bind-Field="@CurrentItem.Name" />
                <EditorItem @bind-Field="@CurrentItem.Price" />

            </FieldItems>
            <Buttons>
                <Button ButtonType="ButtonType.Submit" Icon="fa fa-save" Text="保存" />
            </Buttons>
        </EditorForm>
    </ValidateForm>

  </GroupBox>
    <Message @ref="MessageElement" />

